package com.taogen.hotcrawler.commons.crawler.impl.abroad;//package com.taogen.hotcrawler.commons.crawler.impl.abroad;
//
//import com.taogen.hotcrawler.commons.crawler.HotProcessor;
//import com.taogen.hotcrawler.commons.entity.Info;
//import org.jsoup.nodes.Document;
//import org.jsoup.nodes.Element;
//import org.jsoup.select.Elements;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.ArrayList;
//import java.util.List;
//
//@Component("RedditHotProcessor")
//public class RedditHotProcessor implements HotProcessor
//{
//    private static final Logger log = LoggerFactory.getLogger(RedditHotProcessor.class);
//
//    @Autowired
//    private BaseHotProcessor baseHotProcessor;
//
//    public static final String DOMAIN = "https://www.reddit.com";
//    public static final String HOT_PAGE_URL = "https://www.reddit.com/hot/";
//    public static final String ITEM_KEY = "_1oQyIsiPHYt6nx7VOmd1sz"; // title: ._eYtD2XCVieq6emjKBH3m , url: SQnoC3ObvgnGjWt90zD9Z
//
//    @Override
//    public List<Info> crawlHotList()
//    {
//        List<Info> list = new ArrayList<>();
//
//        // document
//        Document doc = baseHotProcessor.getDoc(HOT_PAGE_URL, null, log);
//        if (doc == null)
//        {
//            return list;
//        }
//
//        // elements
//        Elements elements = doc.getElementsByClass(ITEM_KEY);
//
//        int i = 0;
//        for (Element element : elements)
//        {
//            try
//            {
//                String infoTitle = element.getElementsByClass("_eYtD2XCVieq6emjKBH3m").get(0).html();
//                StringBuilder infoUrl = new StringBuilder();
//                infoUrl.append(DOMAIN);
//                infoUrl.append(element.getElementsByClass("SQnoC3ObvgnGjWt90zD9Z").get(0).attr("href"));
//                String id = String.valueOf(++i);
//                list.add(new Info(id, infoTitle, infoUrl.toString()));
//            }
//            catch(IndexOutOfBoundsException e)
//            {
//                log.error("Can't find attribute!", e);
//            }
//        }
//
//        return baseHotProcessor.handleData(list);
//    }
//}
